package day7;

import java.util.*;

public class Ball {

    //先保存机器要生成的红号和蓝号
    static Set<Integer> red=new TreeSet<>();//有序的 可以对String 数字类型做自然排序 其他对象要用比较器
    static Integer blue;
    //还需保存用户需要的红、蓝号
    static Set<Integer> userRed=new TreeSet<>();
    static Integer userBlue;
    //相同红号数量
    static int readCount;
    //相同蓝号数量
    static int blueCount;
    public static void main(String[] args) throws InterruptedException {
        Set set=new HashSet();//HashMap()
        set.add(null);//map.put()
        Map map=new HashMap();
        map.put(null,null);

        Scanner sc=new Scanner(System.in);
        System.out.println("请输入你6个红号(1-33)");
        while (userRed.size()<6){
            int n=sc.nextInt();
            if(n<1 || n>33) continue;
            userRed.add(n);
        }
        System.out.println("请输入蓝号(1-16)");
        while (true){
            int n=sc.nextInt();
            if(n<1 || n>16) continue;
            userBlue=n;
            break;
        }
        System.out.println("您投注的红号:"+userRed+"蓝号"+userBlue);
        System.out.println("系统生成双色球号，请等待...3s");
        for(int i=0;i<3;i++){
            Thread.sleep(1000);//睡眠1s
            System.out.println("请稍等..."+(3-i)+"s");
        }
        //给红球赋值
        Random r=new Random();
        while (red.size()<6){
            red.add(r.nextInt(33)+1);
        }
        blue=r.nextInt(16)+1;
        System.out.println("双色球生成成功");
        System.out.println("红号"+red+","+"蓝号"+blue);
        //结果1：统计 红球和篮球的相同个数
        stats();
        //结果2：计算金额
        result();
    }
    public static void stats() throws InterruptedException {
        //交集
        System.out.println("统计结果...");
        Thread.sleep(1000);
        Set<Integer> newSet=new TreeSet<>(userRed);
        newSet.retainAll(red);//统计相同的部分
        readCount= newSet.size();
        if(blue==userBlue) blueCount++;
        System.out.println("您中了"+readCount+"红号"+blueCount+"蓝号");
    }
    public static void result(){
        if(readCount<=2&&blueCount==1) System.out.println("六等奖，5元");
        else if(readCount==4&&blueCount==0 || readCount==3&&blueCount==1) System.out.println("五等奖，10元");
        else if(readCount==5&&blueCount==0 || readCount==0&&blueCount==1) System.out.println("四等奖,200元");
        else if(readCount==5&&blueCount==1) System.out.println("四等奖,200元");
        else if(readCount==6&&blueCount==0) System.out.println("四等奖,200元");
        else if(readCount==5&&blueCount==1) System.out.println("四等奖,200元");
        else System.out.println("很遗憾 您没有中奖");
    }
}
